package cn.smdq.ch.code.generator.modules;

import cn.smdq.ch.code.generator.config.GenerationConfigBuilder;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.InjectionConfig;
import com.baomidou.mybatisplus.generator.config.*;

/**
 * @Description 通用权限系统的配置
 * @Author shuimodanqing
 * @Date 2019/1/18  3:24 PM
 */
public class UPMSGenerator {

    public static void execute() {

        AutoGenerator mpg = new AutoGenerator();

        //1. 构建代码生成的输出路径
        String outputDir = GenerationConfigBuilder.buildOutputDir("hope-modules/upms-admin");
        //2. 全局配置
        GlobalConfig gc = GenerationConfigBuilder.buildGlobalConfig(outputDir + "/src/main/java");
        //3. 策略配置 - 包含的表
        String[] includeTable =
                new String[]{"system_dept", "system_permission", "system_oauth_client_details",
                "system_role", "system_user","system_user_role","system_role_permission",
                        "system_role_dept","system_dept_relation","system_routes"};
        StrategyConfig sc = GenerationConfigBuilder.buildStrategyConfig("system", null, null, null, includeTable);
        //4. 包配置
        PackageConfig pc = GenerationConfigBuilder.buildPackageConfig("cn.smdq.ch.upms.admin");
        //5. 数据源配置
        DataSourceConfig dsc = GenerationConfigBuilder.buildDataSourceConfig();
        //6. 自定义mapper.xml输出目录
        InjectionConfig cfg = GenerationConfigBuilder.buildInjectionConfig(outputDir);
        //7. 开始构建
        mpg.setDataSource(dsc);
        mpg.setStrategy(sc);
        mpg.setPackageInfo(pc);
        mpg.setGlobalConfig(gc);
        mpg.setCfg(cfg);
        // 取消默认的xml生成模版
        mpg.setTemplate(new TemplateConfig().setXml(null));
        //8. 开始执行
        mpg.execute();
    }

}
